package com.dc.designPattern._18_memento.extend.extend1;

/**
 * Description: 备忘录模式扩展_客户端
 *
 *  配合原型模式，完成对数据的备份，实现省略备忘录角色的目的
 *
 * @author: gdc
 * @date: 2021/7/8
 * @version 1.0
 */
public class Client {

    public static void main(String[] args){
        // 原始对象
        Originator originator = new Originator("心情好好...");
        System.out.println("初始的状态为：" + originator.getState());

        // 创建备忘录对象
        Originator backupOriginator = originator.createMemento();

        // 创建备忘录管理对象，并保存备忘录对象
        Caretaker caretaker = new Caretaker();
        caretaker.setOriginator(backupOriginator);

        // -----------------------------------------------------------

        originator.setState("略烦躁....");
        System.out.println("后来的状态为：" + originator.getState());

        // -----------------------------------------------------------

        originator.restoreMemento(caretaker.getOriginator());
        System.out.println("恢复的状态为：" + originator.getState());
    }
}
